package com.dyz.leetcode._16_dataStructureDesign;

import java.util.Arrays;

public class _622_MyCircularQueue {
    int [] array;
    int k;
    int left;
    int right;
    public _622_MyCircularQueue(int k) {
        this.k = k;
        this.array = new int[k];
        this.left = k;
        this.right = k;
        Arrays.fill(array, -1);


    }

    public boolean enQueue(int value) {
        if(isFull()){
            return false;
        }
        array[right%k] = value;
        ++right;
        return true;

    }

    public boolean deQueue() {
        if(isEmpty()){
            return false;
        }
        array[left%k] = -1;
        ++left;
        return true;

    }

    public int Front() {
        return array[left%k];

    }

    public int Rear() {
        return array[(right-1)%k];

    }

    public boolean isEmpty() {
        return left==right;

    }

    public boolean isFull() {
        return (right-left)==k;

    }
}
